import 'package:flutter_taotaoshipin/http/request/darma_home_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_banner_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_flower_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_interact_info_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_list_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_main_info_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_main_list_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_main_search_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_play_rand_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_play_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_ranking_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_titbit_list_request.dart';
import 'package:flutter_taotaoshipin/http/request/drama_type_all_request.dart';
import 'package:flutter_taotaoshipin/model/base_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_banner_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_detail_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_flower_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_home_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_interact_info_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_list_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_main_info_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_main_list_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_main_search_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_play_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_play_rand_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_ranking_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_titbit_list_entity.dart';
import 'package:flutter_taotaoshipin/model/drama_type_all_entity.dart';
import 'package:hi_net/hi_net.dart';

class DramaDao {
  /// 获取首页轮播图
  static Future<BaseEntity<List<DramaBannerEntity>>>
      getDramaBanner() async {
    var request = DramaBannerRequest();
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaBannerEntity>>.fromJson(result);
  }

  /// 首页推荐主剧
  static Future<BaseEntity<List<DramaHomeEntity>>>
      getDramaHome() async {
    var request = DarmaHomeRequest();
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaHomeEntity>>.fromJson(result);
  }

  /// 获取剧场总分类json字段集合
  static Future<BaseEntity<List<DramaTypeAllEntity>>>
      getDramaTypeAll({String sort = 'desc'}) async {
    var request = DramaTypeAllRequest();
    request.add('sort', sort);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaTypeAllEntity>>.fromJson(result);
  }

  /// 获取主剧集列表
  static Future<BaseEntity<List<DramaMainListEntity>>>
      getDramaMainList(
    int? type, {
    String sort = 'desc',
    int csjTv = 1,
    int pageIndex = 1,
    int pageSize = 10,
    int csjAppid = 5495906,
  }) async {
    var request = DramaMainListRequest()..add('sort', sort);
    if (type != null) {
      request.add('type', type);
    }
    request.add('csj_tv', csjTv);
    request.add('page_index', pageIndex);
    request.add('page_size', pageSize);
    request.add('csj_appid', csjAppid);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaMainListEntity>>.fromJson(result);
  }

  /// 获取主剧详情
  static Future<BaseEntity<DramaMainInfoEntity>>
      getDramaMainInfo(int id, String title) async {
    var request = DramaMainInfoRequest();
    request.add('id', id).add('title', title);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<DramaMainInfoEntity>.fromJson(result);
  }

  /// 获取分集列表数据
  /// dramaId: 主剧id
  static Future<BaseEntity<List<DramaListEntity>>> getDramaList(
      int dramaId) async {
    var request = DramaListRequest();
    request.add('drama_id', dramaId);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaListEntity>>.fromJson(result);
  }

  /// 获取分集视频详情
  /// id: 分集ID
  static Future<BaseEntity<DramaDetailEntity>> getDramaDetail(
      int id) async {
    var request = DramaMainInfoRequest();
    request.add('id', id);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<DramaDetailEntity>.fromJson(result);
  }

  /// 获取排行榜
  static Future<BaseEntity<List<DramaRankingEntity>>>
      getDramaRanking() async {
    var request = DramaRankingRequest();
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaRankingEntity>>.fromJson(result);
  }

  /// 发现好剧
  static Future<BaseEntity<DramaPlayRandEntity>>
      getDramaPlayRand() async {
    var request = DramaPlayRandRequest();
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<DramaPlayRandEntity>.fromJson(result);
  }

  /// 主剧搜索
  static Future<BaseEntity<List<DramaMainSearchEntity>>>
      getDramaMainSearch(String name) async {
    var request = DramaMainSearchRequest();
    request.add('name', name);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaMainSearchEntity>>.fromJson(result);
  }

  /// 花絮列表
  static Future<BaseEntity<List<DramaFlowerEntity>>>
      getDramaFlower() async {
    var request = DramaFlowerRequest();
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaFlowerEntity>>.fromJson(result);
  }

  /// 获取主剧额外视频列表
  static Future<BaseEntity<List<DramaTitbitListEntity>>>
      getDramaTitbitList({
    required int typeId,
    required int dramaId,
  }) async {
    var request = DramaTitbitListRequest();
    request.add('type_id', typeId);
    request.add('drama_id', dramaId);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<List<DramaTitbitListEntity>>.fromJson(result);
  }

  /// 获取主剧额外视频详情
  static Future<BaseEntity> getDramaTitbitDetails({
    required int id,
    required int dramaId,
  }) async {
    var request = DramaTitbitListRequest();
    request.add('id', id);
    request.add('drama_id', dramaId);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity.fromJson(result);
  }

  /// 主剧互动数据
  static Future<BaseEntity<DramaInteractInfoEntity>>
      interactInfo({
    required int dramaId,
  }) async {
    var request = DramaInteractInfoRequest();
    request.add('drama_id', dramaId);
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<DramaInteractInfoEntity>.fromJson(result);
  }

  /// 发现好剧（全）
  static Future<BaseEntity<DramaPlayEntity>> play() async {
    var request = DramaPlayRequest();
    var result = await HiNet.getInstance().fire(request);
    return BaseEntity<DramaPlayEntity>.fromJson(result);
  }
}
